469B - Chat Online - CodeForces Solution


implementation *1300

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

#define all(x)      x.begin(),x.end()
#define allr(x)     x.rbegin(),x.rend()
#define ll          long long
#define pb(n)       push_back(n);
#define forn(i,n)   for(ll i=0; i<n; i++)
#define fors(i,s)   for(ll i=0; i<s.size(); i++)
#define forv(i,v,n) for(ll i=v; i<n; i++)
#define taha        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define tests       ll t;  cin>>t; while(t--)
#define endl        '\n'
template < typename type >
void operator<<(ostream& out, vector<type> v){
    for(auto i : v)
        out << i << ' '; 
}
ll mn = 1e9, mx = -1e9, mod = 1e9+7, a1, a2, a3;

void solve();


int main(){
    taha

    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

void solve(){
    ll p, q, l, r;  cin >> p >> q >> l >> r;
    vector<bool> ans(r - l + 1);   
    vector<pair<ll, ll>> v1(p), v2(q);
    forn(i, p)
        cin >> v1[i].first >> v1[i].second;
    forn(i, q)
        cin >> v2[i].first >> v2[i].second;
    
    forn(i, q){
        forn(j, p){
            for(int u = 0; u < r - l + 1; u++){
                if(v2[i].first + l + u >= v1[j].first && v2[i].first + l + u <= v1[j].second)
                    ans[u] = 1;
                if(v2[i].second + l + u >= v1[j].first && v2[i].second + l + u <= v1[j].second)
                    ans[u] = 1;
                if(v2[i].first + l + u <= v1[j].first && v2[i].second + l + u >= v1[j].second)
                    ans[u] = 1;
            }
        }
    }
    ll sum = 0;
    forn(i, r - l + 1){
        sum+=ans[i];
    }
    cout << sum;
}


Comments

Submit
0 Comments
More Questions

1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game